<html>
<body>
<p>
<a href="#apibackend" target="_SELF"><b>backend/api.php</b></a>
<ul>
<li><a href="#friends" target="_SELF">friends</a></li>
<li><a href="#friendsrequests" target="_SELF">friendsrequests</a></li>
<li><a href="#league" target="_SELF">league</a></li>
<li><a href="#leagueinvite" target="_SELF">leagueinvite</a></li>
<li><a href="#leaguescoreboard" target="_SELF">leaguescoreboard</a></li>
<li><a href="#messages" target="_SELF">messages</a></li>
<li><a href="#player" target="_SELF">player</a></li>
<li><a href="#team" target="_SELF">team</a></li>
<li><a href="#user" target="_SELF">user</a></li>
</ul>
<a href="#loginbackend" target="_SELF"><b>backend/login.php</b></a>
<ul>
<li><a href="#login" target="_SELF">login</a></li>
<li><a href="#logout" target="_SELF">logout</a></li>
<li><a href="#validate" target="_SELF">validate</a></li>
</ul>
</p>
<h2><a name=apibackend">Backend/api.php</a></h2>

<p><h3><a name="friends">friends</a></h3>
method=friends<br />

<b>GET</b><br />
require id<br />
Get all the friends of user "id".<br />
http://kabanja.se/manager/backend/api.php?method=friends&id=USERID<br />
return an array with all friends to the user with id=USERID.<br />

<b>POST</b><br />
requires accesstoken + auid+id.<br />
requires there to exsist a friendrequest.<br />
method=friends&accesstoken=THEACCESSTOKEN&auid=USERID&id=FRIENDID<br />
returns 200 if sucefull <br />
400 if something went wrong and <br />
401 if you are not loged in. <br />
<b>DELETE</b><br />
requires accesstoken+auid+id <br />
method=friends&accesstoken=THEACCESSTOKEN&auid=USERID&id=FRIENDID<br />
returns 200 if sucessfull 400 if can't find that Id and 401 if you are unautorized<br /></p>
<p><h3><a name="friendsrequests">friendrequests</a></h3>
method=friendrequests<br />

<b>GET</b><br />
requires accesstoken+auid<br />
http://kabanja.se/manager/backend/api.php?method=friendrequests&auid=THEUSERID&accesstoken=THEACCESSTOKEN<br />
Returns an array with all user ids that friend requested you. <br />
accestoken+auid to get all you friendrequest<br />
OR <br />
accesstoken+auid+"friend id" to get a specific friendrequest <br />

<b>POST</b><br />
requires accesstoken+auid+id<br />
method=friendrequests&auid=THEUSERID&accesstoken=THEACCESSTOKEN&id=FRIENDID<br />
returns http status code.<br />

<b>DELETE</b><br />
requires accesstoken+auid+id<br />
method=friendrequests&auid=THEUSERID&accesstoken=THEACCESSTOKEN&id=FRIENDID<br />
returns http status code.<br /></p>
<p><h3><a name="league">league</a></h3>
method=league<br />

<b>GET</b><br />
https://www.kabanja.se/manager/backend/api.php?method=league<br />
Could return something similar to this: [{"id":"83","name":"4myfriends","type":"0","closed":"0","owner":"46","moneylimit":"30000","draftlimit":"5","description":"I'll get by","playerlimit":"18","securitylevel":"2","league":null},{"id":"81","name":"invite only","type":"0","closed":"0","owner":"46","moneylimit":"30000","draftlimit":"20","description":"VIP","playerlimit":"13","securitylevel":"3","league":null},....]<br />
possible parameters:<br />
moneylimit<br />
draftlimit<br />
playerlimit<br />
sortby (draftlimit, playerlimit etc)<br />
order (ASC OR DESC)<br />
startat (where to start showing leagues)<br />
shownr (how many leagues to show)<br />
count (if this paramater = 'true' you will get the number of rows in the result)<br />

<b>POST</b><br />
requires accessotken+auid and leagueid OR leaguename <br />
This method is used to create new league or edit an existing league<br />
method=league?moneylimit=NEWMONEYLIMIT&playerlimit=NEWPLAYERLIMIT&leagueid=THELEAGUEID<br />
return http status code. <br />
possible parameters:<br />
moneylimit<br />
draftlimit<br />
playerlimit<br />
description<br />
securitylevel<br />
newname<br />
Note that the parameters you don't send with the post will be set to empty.<br /></p>

<p><h3><a name="leagueinvite">leagueinvite</a></h3>
method=leagueinvite<br />

<b>POST</b><br />
requires accesstoken+auid+userid+leagueid<br />
method=leagueinvite&accesstoken=THEACCESSTOKEN&auid=THEAUID&userid=THEUSERID&leagueid=THELEAGUEID
returns http status code.
You can only invite players to leagues you own yourself.<br /></p>

<p><h3><a name="leaguescoreboard">leaguescoreboard</a></h3>
method=leaguescoreboard<br />

<b>GET</b><br />
requires id.<br>
https://www.kabanja.se/manager/backend/api.php?method=leaguescoreboard&id=LEAGUEID<br />
Could return something similar to this: [{"id":"54","owner":"45","lw":"13","ce":"127","rw":"7","ld":"159","rd":"56","gk":"182","points":"42.6","bank":"18000","name":"invite onlyTobias","drafts":"12"},{"id":"52","owner":"46","lw":"217","ce":"242","rw":"180","ld":"112","rd":"79","gk":"303","points":"34.4","bank":"18000","name":"invite onlypeter","drafts":"13"}]<br />
<b>id</b>of the league to get a scoreboard for <br />
</p>
<p>
<h3><a name="messages">messages</a></h3>
method=messages<br />

<b>GET</b><br />
requires accesstoken+auid<br />
https://www.kabanja.se/manager/backend/api.php?method=messages&auid=THEAUID&accesstoken=THEACCESSTOKEN
will return something like this: [{"id":"100","from":"48","to":"52","subject":"subject","text":"","timestamp":"2012-01-05 13:45:35","read":"0","type":"0"},{"id":"97","from":"46","to":"48","subject":"hello!","text":"Yes I am here!","timestamp":"2011-12-15 09:40:18","read":"0","type":"0"},{"id":"96","from":"48","to":"46","subject":"Ping","text":"U there?","timestamp":"2011-12-15 09:40:09","read":"0","type":"0"},{"id":"95","from":"48","to":"46","subject":"League invite","text":"85","timestamp":"2011-12-15 09:37:36","read":"0","type":"2"},...]<br />
or a http status code that tells you that something went wrong.<br />
by <b>id</b><br />
OR<br />
action= 'from' or 'to'<br />
optinal parameters<br />
order (ASC or DESC)<br />
sortby (collum to sortby)<br />
postid (which message to show)<br />

<b>POST</b><br />
requires accesstoken+auid+username<br />
method=messages&accesstoken=THEACCESSTOKEN&username=THEUSERNAME&type=0&subject=THESUBJECT&msg=THEMESSAGE&auid=THEAUID<br />
200 is succesfull<br />
400 the user you trying to send to doesnt exsist<br />
401 You'r not loged in<br />
username (who the message is for)<br />
subject<br />
msg<br />
type (0 is regular message 1 is friends request and 2 is league invite)<br />

<b>DELETE</b><br />
requires accesstoken+auid+id<br />
method=messages&accesstoken=THEACCESSTOKEN&auid=THEAUID&id=THEMESSAGEID<br />
200 if sucessfull<br />
404 if the messages isn't found<br />
401 if you are UNAUTHORIZED<br /></p>

<p><h3><a name="player">player</a></h3>
method=player<br />

<b>GET</b><br />
https://www.kabanja.se/manager/backend/api.php?method=player<br />
Returns something like this: [{"id":"215","position":"CE","firstname":"Chris","lastname":"Abbott","team":"LHF","score":"6","assist":"10","stats":"6","price":"2000","saving":"0","nrofteams":"1","pentalybox":"28","totalscoreforteams":"38.4"},{"id":"359","position":"GK","firstname":"Oscar","lastname":"Ahlsenfelt","team":"V\u00c4X","score":"0","assist":"0","stats":"-1","price":"2000","saving":"90.46","nrofteams":"1","pentalybox":"0","totalscoreforteams":"-1"},....]<br />
Or a http status code that tells you something went wrong<br />
optional parameters:<br />
id (for a specific player)<br />
firstname<br />
lastname<br />
position<br />
team<br />
sortby (ASC or DESC)<br />
order (the collum to order by)<br />
startat <br />
shownr (the number of maximum players to return)<br /></p>

<p><h3><a name="team">team</a></h3>
method=team<br />

<b>GET</b><br />
https://www.kabanja.se/manager/backend/api.php?method=team&id=TEAMID<br />
will return something like this: [{"id":"61","owner":"46","lw":"1602","ce":"1602","rw":"1602","ld":"1602","rd":"1602","gk":"1602","points":"0","bank":"10000","name":"My own leaguepeter","drafts":"10","league":"85"}]<br />
or a http status code that tells you that something went wrong.
possible paramaters:<br />
id<br />
name<br />
owner<br />
order(ASC or DESC)<br />
sortby (the collum to sort by)<br />
starat (the team to start at listing at)<br />
shownr (the number of maximum responses)<br />

<b>POST</b><br />
requires accesstoken+auid+newplayer+id<br />
method=team&accesstoken=THEACCESSTOKEN&auid=THEAUID&newplayer=PLAYERID&id=TEAMID<br />
200 if ok<br />
400 in case of some error<br /> 
401 if you're not logged in<br />
Should only be used to change information on a team<br />
For example to buy players. Requires the new player to follow the restrains on the team (nr of drafts etc)<br />
requires valid login (accesstoken+auid)<br />
newplayer (a new player to change to)<br />
id (of the team to change)<br /></p>

<p><h3><a name="user">user</a></h3>
method=user<br />

<b>GET</b><br />
returns a user based on user <b>id</b> OR <b>username</b><br />
http://kabanja.se/manager/backend/api.php?user=friends&username=THEUSERNAME<br />
returns an array with all the information about the user or a http status code if the username does not exist.<br />
Could look something like this: [{"id":"47","username":"kabbe","mail":"something@inter.net","firstname":"Tobias","lastname":"M\u00e4kitalo","location":"Lule\u00e5","age":"22","friends":"","description":"asd"}]<br />

<b>POST</b><br />
creates a new user or if you supply accesstoken+auid it changes your userinformation<br />
parameters:<br />
username<br />
password<br />
mail<br />
firstname<br />
lastname<br />
age<br />
location<br />
description<br />
method=friends&username=NEWUSERNAME&password=NEWPASSOWRD&mail=NEWMAIL&firstname=NEWFIRSTNAME<br />
returns http status code.<br />

<b>DELETE</b><br />
requires accesstoken+auid<br />
method=friends&accesstoken=THEACCESSTOKEN&auid=THEAUID<br />
Deletes a user all his friendrequests,friends,leagues,messages and teams, however this function does not cascade delete, should not be used.<br /></p>

<h2><a name="loginbackend">Backend/Login.php</a></h2>

<p><h3><a name="login">login</a></h3>
method=login
<b>GET</b><br />
To login a user you make a get request to login.php with method=login username=THEUSERNAME and password=THEPASSWORD<br>
it will look something like this: http://www.kabanja.se/manager/backend/login.php?method=login&username=example.'&password=somepassword<br>
You will recieve a json file looking something like this: [{"loggedin":true,"id":"THEUSERID","accesstoken":THEACCESSTOKEN,"username":"example"}]<br>
If it fails you will get a http status code != 200.</p>

<p><h3><a name="logout">logout</a></h3>
method=logout
<b>GET</b><br />
To login a user you make a get request to login.php with method=logout id=THEUSERID and accesstoken=THEACCESSTOKEN<br>
it will look something like this: http://kabanja.se/manager/backend/login.php?method=logout&id=THEUSERID&accesstoken=THEACCESSTOKEN<br>
If it fails you will get a http status code != 200.</p>

<p><h3><a name="validate">validate</a></h3>
method=validate<br />
<b>GET</b><br />
To validate a users accesstoken use login.php with method=validate id=THEUSERID and accesstoken=THEACCESSTOKEN<br>
it will look something like this: http://kabanja.se/manager/backend/login.php?method=validate&id=THEUSERID&accesstoken=THEACCESSTOKEN<br>
it will return a json like thi s: [{"valid":true}].</p>

</body></html>